<template>
    <scroll-view 
        :scroll-y="true"
        class="yf_details_view">
        <view class="container">
            <view class="title el-after">
                当前病人信息
            </view>
            <view class="one">
                <view class="top">
                    <view>
                        挂号单：{{rid}}
                    </view>
                    <view>
                        姓名：{{name}}
                    </view>
                </view>            
            </view>
            <u-button
               type="success"
               @click="onSend">
               发药
            </u-button>
            <u-table>
                <u-tr>
                    <u-th>药品名称</u-th>
                    <u-th>药品数量</u-th>
                </u-tr>
                <view class="table_container">
                    <u-tr 
                        v-for="(item,index) in dataList.drugs" 
                        :key="index">
                        <u-td>{{item.Dname}}</u-td>
                        <u-td>{{item.num}}</u-td>
                    </u-tr>
                </view>
            </u-table>
            <u-toast ref="uToast" />
        </view>
    </scroll-view>
</template>

<script>
//药房发药视图
import {updateRegister,getDrugYaoDan} from "@/common/api";
export default {
    data() {
        return {
            loading:false,
            rid:'',  //挂单号
            name:'',  //用户姓名
            dataList:[],  //药单列表
        };
    },
    onLoad(option) {
        this.rid = option.rid;
        this.name = option.name;
        this.getDrugYaoDan();
    },
    methods: {
        onSend(){  //发药
            this.loading = true;
            updateRegister(
                {
                    rid:this.rid,
                    Status:2,
                },
            ).then(data=>{
                this.$refs.uToast.show({
                    title: "发药成功",
                    position:'top',
                    type: 'success',
                });
                //成功后返回上一个页面
                setTimeout(()=>{
                    uni.navigateBack();
                },1000);
            }).finally(()=>{
                this.loading = false;
            }).catch(msg=>{
                this.$refs.uToast.show({
                    title: msg,
                    position:'top',
                    type: 'error',
                });
            });
        },
        getDrugYaoDan(){  //获取当前病人的药单
            getDrugYaoDan(
                {
                    Rid:this.rid,
                },
            ).then(data=>{
                this.dataList = data;
            });
        },
    },
}
</script>
<style scoped lang="scss">
    .yf_details_view{
        height: calc(100vh);
        .container{
            padding: 35rpx;
            box-sizing: border-box;
            .title{
                width: fit-content;
                font-size: 45rpx;
                color: #000000;
                font-weight: bold;
                margin-bottom: 35rpx;
            }
            >.one{
                box-sizing: border-box;
                display: grid;
                grid-gap: 35rpx;
                font-size: 30rpx;
                margin-bottom: 35rpx;
                >.top{
                    display: grid;
                    grid-template-columns: 1fr 1fr;
                }
                >.content{
                    display: grid;
                    grid-template-columns: 1fr 2fr;
                }
            }
            .u-table{
                margin-top: 35rpx;
                display: block;
            }
        }
    }
</style>
